﻿
<?php
      ob_clean();
header('Content-type:text/html;charset=utf-8');
// print_r($_POST);EXIT;


            	$id = $_GET['id'];


                if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
                    //先查询是否有子级
                    $sql = "select * from `cate` where `pid`=$id";

                    $result = mysqli_query($link,$sql);

                    echo ($result->num_rows>=0)?1:0;
                    die;
                }

             $row = getCateDel($id);


                     if($row>=0){

                             echo '<script>alert("分类删除成功");location.href="index.php?c=cate&a=list&admin=1"; </script>';

                        }else{

                echo '<script>alert("分类删除失败");history.go(-1) </script>';
            }

                //循环逐一去查询每个分类下是否有子级
              function getCateDel($pid=0){

                $sql = "select * from `cate` where pid=$pid";

                $result = mysqli_query($GLOBALS['link'],$sql);

                   //说明有子级
                if($result->num_rows>0){

                    while ($arr = mysqli_fetch_assoc($result)) {
                         getCateDel($arr['id']);
                    }
                }

                   //删除所有分类数据
                del($GLOBALS['c'],$pid);
              }



?>